﻿using System;
using System.Collections.Generic;
using System.Text;
using Kitware.VTK;

namespace Fu3DEngine
{
    [Serializable ]
    public class CylinderNode : CPNodeBase 

    {

        CPCylinder m_ent;
        public CylinderNode(CPCylinder ent,string id):base(id)
        {
            m_ent = ent;
            
        }

        public override void Run()
        {
            base.Run();
            CreateCylinder(m_ent);

        }

        public override void ReLoad()
        {
            throw new NotImplementedException();
        }

        public void CreateCylinder(CPCylinder cy)
        {
            vtkCylinderSource cylinder = new vtkCylinderSource();
            cylinder.SetHeight(cy.height);
            cylinder.SetRadius(cy.radius);
            cylinder.SetResolution(12);

            cylinder.SetCenter(0, cy.height / 2, 0);
            //cylinder.SetCenter(0, 0, 0);


            vtkTransform tran = new vtkTransform();
            tran.RotateX(90);


            vtkTransformFilter tf = new vtkTransformFilter();
            tf.SetInput(cylinder.GetOutput());
            tf.SetTransform(tran);


            m_Poly.m_Data = tf.GetPolyDataOutput();

            //vtkPolyDataMapper mapper =  vtkPolyDataMapper.New();
            ////mapper.SetInput(cylinder.GetOutput());
            //mapper.SetInput(tf.GetPolyDataOutput());
            //// mapper.SetInput(tf.GetPolyDataOutput());


           // vtkActor actor = new vtkActor();



            m_Poly.m_Mapper.SetInput(tf.GetPolyDataOutput());


            m_Poly.m_Actor.SetPosition(cy.x, cy.y, cy.z);

            m_Poly.m_Actor.GetProperty().SetAmbientColor(cy.m_color.R, cy.m_color.G, cy.m_color.B);
            m_Poly.m_Actor.GetProperty().SetDiffuseColor(cy.m_color.R, cy.m_color.G, cy.m_color.B);



            this.SParent.m_vtkRenderer.AddActor(m_Poly.m_Actor);











        }
    }
}
